using System;
using System.Globalization;
using System.Xml;

using Atomic.Libraries.Mathematics;

namespace Atomic.Vasp
{
	internal static class VaspXmlExtensions
	{
		public static XmlNode FindNode(this XmlNode parentNode, string type, string name)
		{
			foreach (XmlNode node in parentNode)
			{
				if (node.Name == type && node.Attributes["name"].Value == name)
				{
					return node;
				}
			}

			return null;
		}

		public static double ToDouble(this XmlNode node)
		{
			return double.Parse(node.InnerText.Trim(), CultureInfo.InvariantCulture);
		}

		public static Vector ToVector(this XmlNode node)
		{
			return AtomicEnvironment.ParseVector(node.InnerText);
		}

		public static SpaceVector ToVector3(this XmlNode node)
		{
			return AtomicEnvironment.ParseSpaceVector(node.InnerText);
		}

		public static Matrix ToMatrix(this XmlNode node)
		{
			throw new NotImplementedException();
			//return AtomicEnvironment.ParseVector(node.InnerText);
		}
	}
}
